package com.huawei.appmarket.service.appdetail.view.activity;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse$ComplaIntegerData;
import com.huawei.appmarket.service.appdetail.bean.report.GeneralResponse$ComplaIntegers;
import com.huawei.appmarket.service.appdetail.bean.report.ReportResponse;
import com.huawei.appmarket.service.appdetail.view.adapter.DetailReportAdapter;
import com.huawei.appmarket.service.appdetail.view.widget.DetailReportCheckBox;
import com.huawei.appmarket.service.appdetail.view.widget.DetailReportProtocol;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.azb;
import o.cfw;
import o.cgv;
import o.cip;
import o.cvt;
import o.BaseRequest;
import o.AsyLoader;
import o.dgm;
import o.Logger;
import o.dof;
import o.drf;
import o.drh;
import o.CollectCheck;
import o.evk;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

public class DetailReportActivity extends BaseActivity<DetailReportProtocol> implements OnClickListener {
    static OnItemClickListener ॱˊ = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
            DetailReportCheckBox detailReportCheckBox = (DetailReportCheckBox) view.findViewById(j.ˋˑ);
            detailReportCheckBox.setChecked(!detailReportCheckBox.isChecked());
        }
    };
    private RelativeLayout ʻॱ;
    private String ʽॱ;
    private String ʾ;
    private DetailReportAdapter ʿ;
    private DetailReportProtocol ˈ;
    private cip ˉ;
    private String ˊˊ;
    private ListView ˊॱ;
    private String ˊᐝ = "selected box";
    protected AsyLoader ˋॱ;
    public List<GeneralResponse$ComplaIntegerData> ˏॱ;
    OnCheckedChangeListener ͺ = new OnCheckedChangeListener(this) {
        final /* synthetic */ DetailReportActivity ॱ;

        {
            this.ॱ = r1;
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            if (!(compoundButton instanceof DetailReportCheckBox)) {
                return;
            }
            if (z) {
                this.ॱ.ᐝॱ.add(((DetailReportCheckBox) compoundButton).ˋ);
            } else {
                this.ॱ.ᐝॱ.remove(((DetailReportCheckBox) compoundButton).ˋ);
            }
        }
    };
    private RelativeLayout ॱˋ;
    private TextView ॱˎ;
    private List<GeneralResponse$ComplaIntegerData> ᐝॱ;

    static class c implements IServerCallBack {
        private cip ʽ;
        private WeakReference<DetailReportAdapter> ˊ;
        private String ˋ;
        private WeakReference<Activity> ˎ;
        private WeakReference<ListView> ˏ;
        private WeakReference<cip> ॱ;
        private List<GeneralResponse$ComplaIntegerData> ॱॱ;

        public c(Activity activity, ListView listView, DetailReportAdapter detailReportAdapter, String str, List<GeneralResponse$ComplaIntegerData> list, cip o_cip) {
            this.ˎ = new WeakReference(activity);
            this.ˏ = new WeakReference(listView);
            this.ˊ = new WeakReference(detailReportAdapter);
            this.ॱ = new WeakReference(o_cip);
            this.ˋ = str;
            this.ॱॱ = list;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            try {
                Activity activity = (Activity) this.ˎ.get();
                ListView listView = (ListView) this.ˏ.get();
                this.ʽ = (cip) this.ॱ.get();
                DetailReportAdapter detailReportAdapter = (DetailReportAdapter) this.ˊ.get();
                if (activity != null && listView != null && detailReportAdapter != null && this.ʽ != null) {
                    if (responseBean instanceof ReportResponse) {
                        ˎ(responseBean, activity);
                    } else if (responseBean instanceof GeneralResponse) {
                        ˎ(responseBean, listView, detailReportAdapter);
                    } else {
                        ˋ();
                        evk.ˋ(activity, activity.getString(n.ॱˉ), 0).ˋ();
                    }
                }
            } catch (Throwable e) {
                Logger.ˋ("DetailAppInfoCard", "notifyResult error", e);
            }
        }

        private void ˎ(ResponseBean responseBean, Activity activity) {
            ˋ();
            int responseCode = responseBean.getResponseCode();
            int i = -1;
            if (responseCode == 0) {
                if (((ReportResponse) responseBean).state_) {
                    evk.ॱ(activity.getString(n.ꜝ), 0).ˋ();
                    activity.finish();
                } else {
                    i = n.ꜟॱ;
                }
            } else if (responseCode == 3) {
                i = n.ʹˊ;
            } else {
                i = n.ꜟॱ;
            }
            if (i > 0) {
                evk.ˋ(activity, activity.getResources().getString(i), 0).ˋ();
            }
        }

        private void ˎ(ResponseBean responseBean, ListView listView, DetailReportAdapter detailReportAdapter) {
            if (responseBean.getResponseCode() == 0) {
                GeneralResponse$ComplaIntegers ॱ = ((GeneralResponse) responseBean).ॱ();
                if (ॱ != null) {
                    Collection ॱ2 = ॱ.ॱ();
                    if (ॱ2 != null && ॱ2.size() > 0) {
                        this.ॱॱ.clear();
                        this.ॱॱ.addAll(ॱ2);
                        for (GeneralResponse$ComplaIntegerData generalResponse$ComplaIntegerData : this.ॱॱ) {
                            if (!dof.ॱ(this.ˋ) && this.ˋ.contains(String.valueOf(generalResponse$ComplaIntegerData.ˎ()))) {
                                generalResponse$ComplaIntegerData.ˎ(true);
                            }
                        }
                        listView.setVisibility(0);
                        detailReportAdapter.notifyDataSetChanged();
                        ˋ();
                    }
                }
            } else if (this.ʽ != null) {
                listView.setVisibility(8);
                this.ʽ.ˏ(responseBean.getResponseCode(), true);
            }
        }

        private void ˋ() {
            if (this.ʽ != null) {
                this.ʽ.ॱ(8);
                this.ʽ = null;
            }
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(h.ˑˋ);
        cgv.ˋ(this, o.ewm.c.ˎ, o.ewm.c.ॱˎ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(o.ewm.c.ॱˎ));
        if (bundle != null) {
            this.ˊˊ = bundle.getString(this.ˊᐝ);
        }
        this.ˈ = (DetailReportProtocol) ʾ();
        if (this.ˈ != null && this.ˈ.ˊ() != null) {
            this.ʽॱ = this.ˈ.ˊ().ˏ();
            this.ʾ = this.ˈ.ˊ().ॱ();
            if (getActionBar() != null) {
                getActionBar().hide();
            }
            ᐝ();
            ॱˊ();
        }
    }

    private void ᐝ() {
        azb.ˏ(findViewById(j.ˈʾ));
        azb.ˏ(findViewById(j.ˋᶦ));
        this.ˊॱ = (ListView) findViewById(j.ˌˈ);
        if (this.ˏॱ == null) {
            this.ˏॱ = new ArrayList();
        }
        if (this.ᐝॱ == null) {
            this.ᐝॱ = new ArrayList();
        }
        this.ʿ = new DetailReportAdapter(this, this.ˏॱ, this.ͺ);
        this.ˊॱ.setAdapter(this.ʿ);
        View findViewById = findViewById(j.ˈʾ);
        this.ʻॱ = (RelativeLayout) findViewById.findViewById(j.ͺˎ);
        this.ॱˋ = (RelativeLayout) findViewById.findViewById(j.ᒽ);
        this.ॱˎ = (TextView) findViewById.findViewById(j.ˈʿ);
        this.ॱˎ.setText(this.ʾ);
        this.ʻॱ.setOnClickListener(this);
        this.ॱˋ.setOnClickListener(this);
        this.ˊॱ.setOnItemClickListener(ॱˊ);
    }

    private void ॱˊ() {
        ͺ();
        cvt o_drh = new drh();
        o_drh.setServiceType_(dgm.ˎ(this));
        this.ˋॱ = cfw.ˎ(o_drh, new c(this, this.ˊॱ, this.ʿ, this.ˊˊ, this.ˏॱ, this.ˉ));
    }

    private void ͺ() {
        if (this.ˉ == null) {
            this.ˉ = new cip();
            this.ˉ.ˎ(findViewById(j.ˋᶦ));
            this.ˉ.ˋ(new OnClickListener(this) {
                final /* synthetic */ DetailReportActivity ॱ;

                {
                    this.ॱ = r1;
                }

                public void onClick(View view) {
                    this.ॱ.ॱˊ();
                }
            });
        }
        this.ˉ.ॱ(0);
    }

    public void onClick(View view) {
        if (view.getId() == j.ͺˎ) {
            finish();
        } else if (view.getId() != j.ᒽ) {
        } else {
            if (this.ᐝॱ.isEmpty()) {
                evk.ˋ(this, getString(n.ꜞॱ), 0).ˋ();
            } else {
                ᐝॱ();
            }
        }
    }

    private void ᐝॱ() {
        cvt o_drf = new drf();
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder stringBuilder2 = new StringBuilder();
        for (GeneralResponse$ComplaIntegerData generalResponse$ComplaIntegerData : this.ᐝॱ) {
            stringBuilder.append(generalResponse$ComplaIntegerData.ˎ()).append(',');
            stringBuilder2.append(generalResponse$ComplaIntegerData.ˊ()).append(',');
        }
        stringBuilder.delete(stringBuilder.length() - 1, stringBuilder.length());
        stringBuilder2.delete(stringBuilder2.length() - 1, stringBuilder2.length());
        o_drf.ˏ(stringBuilder2.toString());
        o_drf.ॱ(stringBuilder.toString());
        o_drf.setServiceType_(dgm.ˎ(this));
        o_drf.ˊ(this.ʽॱ);
        ͺ();
        cfw.ˎ(o_drf, new c(this, this.ˊॱ, this.ʿ, this.ˊˊ, this.ˏॱ, this.ˉ));
    }

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        if (!CollectCheck.isEmpty(this.ᐝॱ)) {
            StringBuilder stringBuilder = new StringBuilder();
            for (GeneralResponse$ComplaIntegerData ˎ : this.ᐝॱ) {
                stringBuilder.append(ˎ.ˎ()).append(',');
            }
            bundle.putString(this.ˊᐝ, stringBuilder.toString());
        }
    }

    public void onConfigurationChanged(Configuration configuration) {
        this.ʿ.clear();
        for (GeneralResponse$ComplaIntegerData generalResponse$ComplaIntegerData : this.ᐝॱ) {
            if (this.ˏॱ.contains(generalResponse$ComplaIntegerData)) {
                ((GeneralResponse$ComplaIntegerData) this.ˏॱ.get(this.ˏॱ.indexOf(generalResponse$ComplaIntegerData))).ˎ(true);
            }
        }
        this.ʿ.notifyDataSetChanged();
        super.onConfigurationChanged(configuration);
    }
}
